﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Windows;
using System.Windows.Input;
// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using BrainTechLLC;
using BrainTechLLC.FilterExtensions;
using ImageAppDataModels;
using ImageAppViewModels;


namespace WpfImageDuplicates
{                            
    public partial class ResizeCommand : RoutedCommand, ICommand
    {
        public void Execute(FileImageViewModel vm, int width, int height)
        {
            if (width <= 0)
                width = vm.FileImage.OriginalBitmapWidth;

            if (height <= 0)
                height = vm.FileImage.OriginalBitmapHeight;

            var thumb = Window1.MainWindow.FindThumbView(vm);

            if (thumb != null)
            {
                Bitmap bm = vm.FileImage.EnsureBitmapLoaded();

                if ((width < height && bm.Width > bm.Height) ||
                    (width > height && bm.Width < bm.Height))
                {
                    int tempHeight = height;
                    height = width;
                    width = tempHeight;
                }
                
                thumb.ResizeCommandTriggered(width, height);
            }
        }
    }
}
